<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css"  media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/plugins/font-awesome-4.7.0/css/font-awesome.min.css"  media="all">
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        layui.use(['form','layer','table'],function () {
            var form = layui.form;
            form.on('submit(goLogin)',function (data) {
                var data=$("#loginForm").serialize();
                $.ajax({
                    url:"${pageContext.request.contextPath}/admin/login1",
                    data:data,
                    dataType:"json",
                    type:"post",
                    success:function (data) {
                        alert(data);
                        if (data==0){
                            location.href = '${pageContext.request.contextPath}/main.jsp';
                        }else if(data==1){
                            alert("密码错误或验证码错误")
                            location.href = '${pageContext.request.contextPath}/login1.jsp';
                        }
                    }
                })
            })

        })

        function changeImage() {
            $("#code").prop("src","${pageContext.request.contextPath}/admin/getCode?t="+new Date().getTime());
        }

    </script>


</head>

<body class="layui-layout-login">
<div class="login-bg">
    <div class="cover"></div>
</div>
<div class="login-content" >
    <h1 class="login-box-title"><i class="fa fa-fw fa-user"></i>登录</h1>
    <form class="layui-form" id="loginForm" lay-filter="loginForm"  >

        <div class="layui-form-item">
            <label class="layui-icon layui-icon-username" for="username"></label>
            <input class="layui-input" type="text" name="username" id="username" placeholder="用户名">
        </div>

        <div class="layui-form-item">
            <label class="layui-icon layui-icon-password" for="password"></label>
            <input class="layui-input" type="password" name="password" id="password" placeholder="密码">
        </div>

        <div class="layui-form-item captcha-item">
            <label class="layui-icon layui-icon-vercode"></label>
            <input class="layui-input" type="text" name="code" autocomplete="off" placeholder="验证码">
            <a href="javascript:changeImage()" ><img class="captcha-img" id="code" src="${pageContext.request.contextPath}/admin/getCode" /></a>
        </div>
            <button class="layui-btn layui-btn-fluid ajax-login" class="layui-btn" lay-submit lay-filter="goLogin"><i class="fa fa-sign-in fa-lg fa-fw"></i> 登录</button>
             <br/><br/>
            <a  href="main.jsp"  class="layui-btn layui-btn-fluid ajax-login"><i class="fa fa-sign-in fa-lg fa-fw"></i> 注册</a>
    </form>
</div>
</body>
</html>
